<template>
  <div class="home">
    <div class="as" v-for="item in property" :key="item.id">
      <img :src="item.pic" alt="" @click="xaGn(item.id)">
        <p>{{item.name}}</p>
        <p>{{item.minPrice}}</p>
        <button @click="jia(item)">加入购物车</button>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default{
  name: 'HomeView',
  data() {
    return {
      property: [],
    };
  },
  created(){
    this.LsiS()
  },
  methods: {
    ...mapMutations(['add']),
    LsiS(){  
      fetch("https://api.it120.cc/xiaochengxu/shop/goods/list")
      .then(res=>res.json())
      .then(res=>{
        // console.log(res);
        this.property=res.data
      })
    },
    jia(item){
      let {id,minPrice,name,pic}=item
      var obj={id,minPrice,name,pic,num:1}
      this.add(obj)
    },
    xaGn(id){
      this.$router.push(`/info?${id}`)
    }
  },
}
</script>
<style>
.home{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  text-align: center;
}
.as{
  /* background: blueviolet; */
  width: 30vw;
}
img{
  width: 300px;
  height: 300px;
}
</style>